package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        Method[] methods = cls.getDeclaredMethods();
        System.out.println(methods.length);
        int a = 0;
        for (int i = 0; i < methods.length; i++) {
            if(methods[i].getParameterCount()==0 && methods[i].getModifiers()== Modifier.PUBLIC
                && methods[i].getName().contains("o")) {
                a++;
                System.out.println(methods[i].getName());
                Method method = cls.getDeclaredMethod(methods[i].getName());
                method.invoke(o);
            }
        }
        System.out.println(a);
        Person p = new Person();
        p.eat();
        System.out.println(p.toString());
    }
}
